<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

use  App\Models\Phone;

use Illuminate\Support\Facades\DB;
use Cache;
use Validator;
use Carbon\Carbon;
use function GuzzleHttp\json_encode;
use \GatewayWorker\Lib\Gateway;
use  App\Models\Weixin;
use  App\Models\User;

use  App\Models\WeixinFriendList;
use  App\Models\ChatMessage;
class TestController extends Controller
{
    public function test()
    {
        // $data['imei'] = '352531082766203';
        // $client_id = '7f00000108fd0000000d';
        // $phone = Phone::where('imei',$data['imei'])->first();
        // if($phone){
        //     $phone->client_id = $client_id;
        //     $phone->save();
        // }
        // $week = Carbon::now()->subDay(7);
        // $month = Carbon::now()->subDay(30);
        // $count = ChatMessage::where('uid','wxid_wo81161r9e5322')->where('created_at','>',$week)->count();
        // var_dump($count);
        // exit;
        // $uid = 'wxid_wo81161r9e5322';
        // $weixin = Weixin::where('uid',$uid)->first();
        // $data['to_weixin_uid'] = 'wxid_d43j73158s8b21';
        // $data['ext']['content'] = '12';
        // $new_message = array(
        //     'type'=>'SEND_MSG_GROUP',
        //     'data' => [
        //         'uid' => [$data['to_weixin_uid']],
        //         'ext' => $data['ext'],
        //         'type' => '1',
        //     ]
        // );
        // // $ss = Gateway::sendToClient('7f00000108fd00000001', json_encode($new_message));
        // $ss = Gateway::sendToAll(json_encode($new_message));
        // dd($ss);
    }    

    protected function check_weixin_online($ids,$client_id)
    {
        $data = Weixin::whereIn('uid',$ids)->select('uid','phone_client_id')->get();
        // foreach ($data as $key => $value) {
        //     $data[$key]['online'] = Gateway::isOnline($value['phone_client_id']);
        // }
        $new_message['data'] = $data;
        $new_message['type'] = 'WECHAT_HEAETBEAT';
        Gateway::sendToAll(json_encode($new_message));
    }
}